package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.query.SystemMessageQueryObject;
import cn.wolfcode.trip.base.service.ISystemMessageService;
import cn.wolfcode.trip.base.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("systemMessages")
public class SystemMessageContoller {
    @Autowired
    private ISystemMessageService systemMessageService;

    /**
     * 获取系统消息列表
     * @param qo
     * @return
     */
    @GetMapping("/{userId}")
    public PageInfo list(SystemMessageQueryObject qo){
        qo.setOrderBy("createTime desc");
        return systemMessageService.query(qo);
    }

    /**
     * 查找未查看的系统消息
     * @param userId
     * @return
     */
    @GetMapping
    public Integer getNoReadCount(Long userId){
        return systemMessageService.getNoReadCount(userId);
    }

    /**
     * 设置系统消息已读
     * @param userId
     * @return
     */
    @PostMapping
    public Object setRead(Long userId){
        systemMessageService.setRead(userId);
        return new JsonResult();
    }

}
